package com.myrabbitmq.mylistener.returnlistener;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

import java.io.IOException;
import java.util.Map;

public class MyConsumer extends DefaultConsumer {
    /**
     * Constructs a new instance and records its association to the passed-in channel.
     *
     * @param channel the channel to which this consumer is attached
     */
    public MyConsumer(Channel channel) {
        super(channel);
    }

    @Override
    public void handleDelivery(String consumerTag,
                               Envelope envelope,
                               AMQP.BasicProperties properties,
                               byte[] body)
            throws IOException
    {
        // no work to do
        String routingKey = envelope.getRoutingKey();
        String contentType = properties.getContentType();
        long deliveryTag = envelope.getDeliveryTag();
        // (process the message components here ...)
        Map<String,Object> head = properties.getHeaders();
        String expiration = properties.getExpiration();
        System.out.println(new String(body, "UTF-8"));
        System.out.println(head);
        System.out.println("过期时间："+expiration);
        System.err.println("===========返回失败=======");
        System.err.println("consumerTag:"+consumerTag);
        System.err.println("envelope:"+envelope);
        System.err.println("routingKey:"+routingKey);
        System.err.println("properties:"+properties);
        System.err.println("body:"+new String(body));
        this.getChannel().basicAck(deliveryTag, false);
    }
}
